package viz_main;

import processing.core.PVector;

public class ScatterPlotAxis
{
  // This class stores data relevant to displaying the axis correctly on the grid view
  // it also supports changing the data and notifying the grid view
  protected int type = 0;
  protected String label = "axis";
  protected PVector range = new PVector(999.0f, 0.0f); // the final min and max bounds of this axis
  protected PVector filteredRange = new PVector(0.0f, 0.0f); // the current visible min and max bounds of this axis
  protected float maxFilter = 0.0f;
  protected float tickCount = 10.0f;
  protected float subTicks = 3; // value you want + 1
  protected float[] values;
  private float sum;
  protected final int rnd = 100; // round values to hundredths.
  
  public ScatterPlotAxis(String axisName, int sz)
  {
    label = axisName;
    values = new float[sz];
  }
  
  public void addElement(String e, int index)
  {
    float tmpVal = Float.parseFloat(e);
    values[index] = tmpVal;
    if(tmpVal > range.y){ 
      range.y = tmpVal; 
      filteredRange.y = tmpVal + ((range.y - range.x)/tickCount); // store a bit bigger than the greatest value
      maxFilter = filteredRange.y;
    }
    if(tmpVal < range.x){ range.x = tmpVal; } // store the minimum value
    sum += tmpVal;
  }
  
  public float getElement(int index)
  {
    return values[index];
  }
  
  public String getElementAsString(int index)
  {
    return String.valueOf(values[index]);
  }
  
  public String getLabel(){
    return label;
  }
  public int getType(){
    return type;
  }
  public PVector getRange(){
    return range;    
  }
  public void setRange(float mi, float ma){
    range = new PVector(mi, ma);
  }
  
  // FILTERING CONTROLS:
  public float getMin(){
    return filteredRange.x;    
  }
  public float getMax(){
    return filteredRange.y;    
  }
  public void setFilteredX(float val){
    filteredRange.x = maxFilter*val;
  }
  public void setFilteredY(float val){
    filteredRange.y = maxFilter*val;
  }
  public void fitToBounds()
  {
    filteredRange.x = range.x;
    filteredRange.y = range.y;
  }
  
  public float getTicks(){
    return tickCount;
  }
  public float getSubTicks(){
    return subTicks;
  }
  public int getLength(){
    return values.length;
  }
  public void setTicks(float main, float subb) { // utility for setting both ticks simultaneously
    tickCount = main;
    subTicks = subb;
  }
  public void setTicks(float main) {
    tickCount = main;
  }
  public void setSubTicks(float subb) {
    subTicks = subb;
  }
  
  public void printContents()
  {
	  for(int i = 0; i < values.length; i++)
	  {
		  System.out.println(values[i]);
	  }
  }
  
  // More complex methods:
  // returns the value that should be contained for this mark:
  public String getMark()
  {
    return "";
  }
}
